package com.intct.hbase.dml;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * @author gufg
 * @since 2025-07-11 10:58
 */
public class GetDataImpl extends AbsDMLBase {

    private String rowkey;
    public GetDataImpl(String rowkey) {
        this.rowkey = rowkey;
    }

    @Override
    public void execCommand(Table table) throws IOException {
        // 查询数据
        Get get = new Get(Bytes.toBytes(rowkey));

        Result result = table.get(get);
        // 列族名称：列限定符：值
        Cell[] cells = result.rawCells();

        for (Cell cell : cells) {
            // 列族名称
            String family = Bytes.toString(CellUtil.cloneFamily(cell));
            // 列限定符（列名）
            String columName = Bytes.toString(CellUtil.cloneQualifier(cell));
            // rowkey
            String rowkey = Bytes.toString(CellUtil.cloneRow(cell));

            // 值
            String value = Bytes.toString(CellUtil.cloneValue(cell));

            System.out.println("列族名称 = " + family + "; 列名 = " + columName + "; 主键 = " + rowkey + "; 值 = " + value);
        }
    }

    public static void main(String[] args) throws IOException {
        new GetDataImpl("1001").start("intct82", "t001");
    }
}
